package de.tum.wi.som;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Node {
	List<Node> successors = new ArrayList<Node>();
	List<Node> predecessors = new ArrayList<Node>();
	double d;
	double start;
	int[] r;
	double earliestStart;
	double latestStart;
	double earliestFinish;
	double latestFinish;

	public Node(int d, int[] r) {
		this.d = d;
		this.r = r;
		this.start = Double.POSITIVE_INFINITY;
	}

	public static void addArc(Node i, Node j) {
		i.successors.add(j);
		j.predecessors.add(i);
	}

	/**
	 * Copies a node, including all attributes, EXCEPT start, successors and
	 * predecessors.
	 * 
	 * @return copy of this node, including all attributes, EXCEPT start,
	 *         successors and predecessors.
	 */
	public Node getCopyOf() {
		Node copy = new Node(new Double(getD()).intValue(), Arrays.copyOf(
				getR(), getR().length));
		copy.setD(d);
		copy.setEarliestFinish(earliestFinish);
		copy.setEarliestStart(earliestStart);
		copy.setLatestFinish(latestFinish);
		copy.setLatestStart(latestStart);
		return copy;
	}

	/**
	 * @return the successors
	 */
	public List<Node> getSuccessors() {
		return successors;
	}

	/**
	 * @param successors
	 *            the successors to set
	 */
	public void setSuccessors(List<Node> successors) {
		this.successors = successors;
	}

	/**
	 * @return the predecessors
	 */
	public List<Node> getPredecessors() {
		return predecessors;
	}

	/**
	 * @param predecessors
	 *            the predecessors to set
	 */
	public void setPredecessors(List<Node> predecessors) {
		this.predecessors = predecessors;
	}

	/**
	 * @return the d
	 */
	public double getD() {
		return d;
	}

	/**
	 * @param d
	 *            the d to set
	 */
	public void setD(double d) {
		this.d = d;
	}

	/**
	 * @return the start
	 */
	public double getStart() {
		return start;
	}

	/**
	 * @param start
	 *            the start to set
	 */
	public void setStart(double start) {
		this.start = start;
	}

	/**
	 * @return the r
	 */
	public int[] getR() {
		return r;
	}

	/**
	 * @param r
	 *            the r to set
	 */
	public void setR(int[] r) {
		this.r = r;
	}

	/**
	 * @return the earliestStart
	 */
	public double getEarliestStart() {
		return earliestStart;
	}

	/**
	 * @return the slack
	 */
	public double getSlack() {
		return latestStart - earliestStart;
	}

	/** * @param earliestStart The earliestStart to set. */
	public void setEarliestStart(double earliestStart) {
		this.earliestStart = earliestStart;
	}

	/** * @return Returns the latestStart. */
	public double getLatestStart() {
		return latestStart;
	}

	/** * @param latestStart The latestStart to set. */
	public void setLatestStart(double latestStart) {
		this.latestStart = latestStart;
	}

	/** * @return Returns the earliestFinish. */
	public double getEarliestFinish() {
		return earliestFinish;
	}

	/** * @param earliestFinish The earliestFinish to set. */
	public void setEarliestFinish(double earliestFinish) {
		this.earliestFinish = earliestFinish;
	}

	/** * @return Returns the latestFinish. */
	public double getLatestFinish() {
		return latestFinish;
	}

	/** * @param latestFinish The latestFinish to set. */
	public void setLatestFinish(double latestFinish) {
		this.latestFinish = latestFinish;
	}

	@Override
	public String toString() {
		return "Node [d=" + d + ", start=" + start + ", r="
				+ Arrays.toString(r) + "]";
	}
}
